var gameObjectTypes = {
	lizardTemple: 0,
	pit: 1,
	lizardMan: 2,
	snakeMan: 3,
	croc: 4,
	bioSphere: 5,
	barracks: 6,
	humanWorker: 7,
	soldier: 8,
	flamer: 9
};

var factions = {
	lizards: 0,
	humans: 1
};

function gameObjectFactory() {

}

gameObjectFactory.prototype.findGameObjectNameById = function(id) {
	for(var goName in gameObjectTypes){
		if(gameObjectTypes[goName] === id) {
			return goName;
		}
	}
	return null;
}

gameObjectFactory.prototype.findGameObjectNameByTemplate = function(template) {
	for(var propertyName in this){
		if(this[propertyName] === template) {
			return propertyName.replace("Template", '');
		}
	}
	return null;
}



gameObjectFactory.prototype.lizardTempleTemplate = {
	friendlyName: 'Lizard Temple',
	faction: factions.lizards,
    width: 96,
    height: 96,
    attackSpeed: 0,
    range: 0,
    health: 100,
    maxHealth: 100,
    damage: 0,
    moveSpeed: 0,
    price: 35,
	profit: 1,
	canBuild: [
		gameObjectTypes.lizardMan,
		gameObjectTypes.snakeMan
	]
}

gameObjectFactory.prototype.pitTemplate = {
	friendlyName: 'Croc Pit',
	faction: factions.lizards,
    width: 96,
    height: 96,
    attackSpeed: 0,
    range: 0,
    health: 75,
    maxHealth: 75,
    damage: 0,
    moveSpeed: 0,
    price: 25,
	profit: 0,
	canBuild: [
		gameObjectTypes.croc
	]
}

gameObjectFactory.prototype.lizardManTemplate = {
	friendlyName: 'Lizard Man',
	faction: factions.lizards,
    width: 32,
    height: 32,
    attackSpeed: 1,
    range: 32,
    health: 10,
    maxHealth: 10,
    damage: 1,
    moveSpeed: 1.5,
    price: 5,
	profit: 0,
	buildTime: 5
}

gameObjectFactory.prototype.snakeManTemplate = {
	friendlyName: 'Snake Man',
	faction: factions.lizards,
    width: 32,
    height: 32,
    attackSpeed: 1,
    range: 128,
    health: 5,
    maxHealth: 5,
    damage: 1,
    moveSpeed: 1,
    price: 10,
	profit: 0,
	buildTime: 10
}

gameObjectFactory.prototype.crocTemplate = {
	friendlyName: 'Croc',
	faction: factions.lizards,
    width: 32,
    height: 32,
    attackSpeed: 3,
    range: 0,
    health: 40,
    maxHealth: 40,
    damage: 15,
    moveSpeed: .5,
    price: 20,
	profit: 0,
	buildTime: 15
}

gameObjectFactory.prototype.bioSphereTemplate = {
	friendlyName: 'BioSphere',
	faction: factions.humans,
    width: 96,
    height: 96,
    attackSpeed: 0,
    range: 0,
    health: 100,
    maxHealth: 100,
    damage: 0,
    moveSpeed: 0,
    price: 40,
	profit: 1,
	canBuild: [
		gameObjectTypes.humanWorker,
		gameObjectTypes.soldier
	]
}

gameObjectFactory.prototype.barracksTemplate = {
	friendlyName: 'Barracks',
	faction: factions.humans,
    width: 96,
    height: 96,
    attackSpeed: 0,
    range: 0,
    health: 65,
    maxHealth: 65,
    damage: 0,
    moveSpeed: 0,
    price: 20,
	profit: 0,
	canBuild: [
		gameObjectTypes.flamer
	]
}

gameObjectFactory.prototype.humanWorkerTemplate = {
	friendlyName: 'Worker',
	faction: factions.humans,
    width: 32,
    height: 32,
    attackSpeed: 1,
    range: 32,
    health: 10,
    maxHealth: 10,
    damage: 1,
    moveSpeed: 1,
    price: 5,
	profit: 0,
	buildTime: 5
}

gameObjectFactory.prototype.soldierTemplate = {
	friendlyName: 'Soldier',
	faction: factions.humans,
    width: 32,
    height: 32,
    attackSpeed: 1,
    range: 64,
    health: 10,
    maxHealth: 10,
    damage: 1,
    moveSpeed: 1,
    price: 8,
	profit: 0,
	buildTime: 8
}

gameObjectFactory.prototype.flamerTemplate = {
	friendlyName: 'Flamer',
	faction: factions.humans,
    width: 32,
    height: 32,
    attackSpeed: .3,
    range: 32,
    health: 5,
    maxHealth: 5,
    damage: 1,
    moveSpeed: 2,
    price: 20,
	profit: 0,
	buildTime: 15
}

gameObjectFactory.prototype.createGameObject = function(id, player, template, tileX, tileY, images, map) {
	return new gameObject(id, player, tileX, tileY, images, this.findGameObjectNameByTemplate(template), template, map);
}
